# -*- coding: utf-8 -*-
# @Time : 2021/9/12 15:09
# @Author : 阿怪
# @Email : 673691277@qq.com
# @File : email_page.py
# @Project : crm自动化测试项目实战
'''邮件模板设置页面类'''

from selenium.webdriver.common.by import By
from page.base_page import BasePage
import time

today = time.strftime('%Y-%m-%d')  # 获取当前日期
from utils.util import HOST2

class EmailPage(BasePage):
    '''邮件设置首页类'''


    #定义定位器
    url = '{}/index.php?m=email&a=index'.format(HOST2)
    # url = 'http://192.168.3.156/crm3/index.php?m=email&a=index'
    add_email_locator = (By.ID, 'add')  # 添加邮件模板定位器
    template_locator = (By.NAME, 'subject')  # 模板名称定位器
    email_tittle_locator = (By.NAME, 'title')  # 邮件主题定位器
    email_text_locator = (By.ID, 'content')  # 邮件内容定位器
    submit_locator = (By.NAME, 'submit')  # 保存按钮定位器
    emailtext_locator = (By.XPATH,'//*[@id="form1"]/div[2]/table/tbody/tr/td[4]')  #首页模板内容定位器
    edit_locator = (By.CSS_SELECTOR, '#form1 > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(5) > a') #【编辑】按钮定位器


    #操作元素方法
    def add_email_click(self):
        '''添加邮件模板按钮'''
        element = self.driver.find_element(*self.add_email_locator)
        element.click()


    def input_template(self, template):
        '''输入模板名称'''
        element1 = self.driver.find_element(*self.template_locator)
        element1.send_keys(template)


    def input_name(self, tittle):
        '''输入模板主题'''
        element2 = self.driver.find_element(*self.email_tittle_locator)
        element2.send_keys(tittle)

    def input_text(self, text):
        '''输入模板内容'''
        element3 = self.driver.find_element(*self.email_text_locator)
        element3.send_keys(text)
        return text

    def edit_email_message(self,template,tittle,text):
        '''编辑邮件模板'''
        self.input_template(template)
        self.input_name(tittle)
        self.input_text(text)



    def email_submit(self):
        '''邮件编辑界面点击【保存】'''
        element = self.driver.find_element(*self.submit_locator)
        element.click()

    def get_emailtext(self):
        '''获取首页第一条邮件【内容】'''
        element = self.driver.find_element(*self.emailtext_locator)
        text = element.text
        return text

    def edit_click(self):
        '''点击【编辑】'''
        element = self.driver.find_element(*self.edit_locator)
        element.click()


    def clear_template(self):
        '''清空模板名称'''
        element1 = self.driver.find_element(*self.template_locator)
        element1.clear()


    def clear_name(self):
        '''清除邮件主题'''
        element2 = self.driver.find_element(*self.email_tittle_locator)
        element2.clear()


    def clear_text(self):
        '''清除邮件内容'''
        element3 = self.driver.find_element(*self.email_text_locator)
        element3.clear()

    def clear_emil(self):
        '''清空邮件编辑界面的输入框内容'''
        self.clear_template()
        self.clear_name()
        self.clear_text()








